package com.ykdl.member.kid.beans;

import java.io.Serializable;
import java.util.ArrayList;

import net.wxxr.http.interfaces.IJsonParser;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;

public class FeedListBean implements Serializable, IJsonParser {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1117537931038498609L;
	private BabyProfileBean baby_profile;
	private ArrayList<Nursing> list = new ArrayList<Nursing>();
	@SerializedName("next_cursor")
	private int nextCursor;
	@SerializedName("total_number")
	private int totalNumber;
	
	public BabyProfileBean getBaby_profile() {
		return baby_profile;
	}

	public void setBaby_profile(BabyProfileBean baby_profile) {
		this.baby_profile = baby_profile;
	}

	public ArrayList<Nursing> getList() {
		return list;
	}

	public void setList(ArrayList<Nursing> list) {
		this.list = list;
	}

	public int getNextCursor() {
		return nextCursor;
	}

	public void setNextCursor(int nextCursor) {
		this.nextCursor = nextCursor;
	}

	public int getTotalNumber() {
		return totalNumber;
	}

	public void setTotalNumber(int totalNumber) {
		this.totalNumber = totalNumber;
	}

	@Override
	public IJsonParser parse(String json) throws Exception {
		if (null != json) {
			GsonBuilder b = new GsonBuilder();
			Gson gson = b.create();
			JSONObject jsonObject = new JSONObject(json);
			this.totalNumber = jsonObject.getInt("total_number");
			this.nextCursor = jsonObject.getInt("next_cursor");
			JSONArray  array = jsonObject.getJSONArray("list");
			JSONObject jo = null;
			Nursing nursing = null;
			for (int i = 0; i < array.length(); i++){
				jo = array.getJSONObject(i);
				int type = jo.getInt("nursing_type");
				switch (type) {
				case 1:
					nursing = gson.fromJson(array.getString(i), Nappy.class);
					break;
				case 2:
					nursing = gson.fromJson(array.getString(i), Sleeping.class);
					break;
				case 3:
					nursing = gson.fromJson(array.getString(i), Feeding.class);
					break;
				case 4:
					nursing = gson.fromJson(array.getString(i), BreastFeeding.class);
					break;
				default:
					nursing = gson.fromJson(array.getString(i), Nursing.class);
					break;
				}
				this.list.add(nursing);
			}
			return this;
		}
		return null;
	}

}
